# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base

  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick

  storage :file

  def store_dir
    "uploads/#{mounted_as}/#{model.id}"
  end

  def filename
		random_token = Digest::SHA2.hexdigest("#{Time.now.utc}--#{model.id.to_s}").first(20)
    ivar = "@#{mounted_as}_secure_token"    
    token = model.instance_variable_get(ivar)
    token ||= model.instance_variable_set(ivar, random_token)
    "#{token}.jpg" if original_filename
  end

   version :carousel do
     process :resize_to_limit => [500, 245]
   end

   version :preview do
     process :resize_to_limit => [210, 150]
   end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

end
